<?php

# Add a new blog entry.

class Insert {
	static public function post() {
		global $Blog_list, $Blog_title, $Blog_text, $Blog_box, $Blog_new_win;

		date_default_timezone_set('Europe/Rome');
		$date = date('c');
		$title_val = $Blog_title->cget('value');
		$text_val = $Blog_text->get(0);

		$db = Db::singleton();
		$st = $db->prepare('INSERT INTO blog (date, title, text) VALUES (?, ?, ?)');
		$st->execute(array($date, $title_val, $text_val));

		# TODO: insert a separator only if there is one or more posts already.
		array_unshift($Blog_list, new Separator());
		array_unshift($Blog_list, Format::post($date, $title_val, $text_val));
		$Blog_box->configure(array('children' => $Blog_list));

		# TODO: What about children?
		# Close new entry window.
		$Blog_new_win->delete();
	}
}

# End of file
# vim: set ts=2 sw=2 noet:
?>
